package com.ticket.api.service.Impl;

import com.ticket.api.service.TblMarketTicketInfoService;
import com.ticket.common.string.StringUtil;
import com.ticket.common.time.CommonFunction;
import com.ticket.db.dao.TblMarketTicketInfoMapper;
import com.ticket.db.entity.TblMarketTicketInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TblMarketTicketInfoServiceImpl implements TblMarketTicketInfoService {

    @Autowired
    TblMarketTicketInfoMapper tblMarketTicketInfoMapper;
    @Override
    public List<TblMarketTicketInfo> findTblMarketTicketInfoAll(String userId) {
        return tblMarketTicketInfoMapper.findTblMarketTicketInfoAll(userId);
    }

    @Override
    public  List<TblMarketTicketInfo> findTblMarketTicketInfoByCondition(TblMarketTicketInfo info) {
        return tblMarketTicketInfoMapper.findTblMarketTicketInfoByCondition(info);
    }

    @Override
    public Integer insertTblMarketTicketInfo(TblMarketTicketInfo info) {
        String time = CommonFunction.getLocalTime14();
        info.setStatus("1");
        info.setPublishTime(time);
        info.setTicketProviedId(StringUtil.getUUID());
        info.setCreateTime(time);
        info.setMessageId(StringUtil.getUUID());
        info.setLastUpdateUser(info.getCreateUser());
        info.setLastUpdateTime( CommonFunction.getLocalTime14());
        return tblMarketTicketInfoMapper.insertTblMarketTicketInfo(info);
    }

    @Override
    public Integer updateTblMarketTicketInfo(TblMarketTicketInfo info) {
        TblMarketTicketInfo marketTicketInfo =new TblMarketTicketInfo();
        marketTicketInfo.setTicketProviedId(info.getTicketProviedId());
        List<TblMarketTicketInfo>  list=  tblMarketTicketInfoMapper.findTblMarketTicketInfoByCondition(marketTicketInfo);
            if(list.size()==0){
                return 0;
            }
        info.setLastUpdateUser(info.getCreateUser());
            info.setLastUpdateTime( CommonFunction.getLocalTime14());
        return tblMarketTicketInfoMapper.updateTblMarketTicketInfo(info);
    }
}
